// AutoPowerOnShutdownDlg.h : header file
//

#pragma once
#include "afxwin.h"
#include "ClockST.h"
#include "afxdtctl.h"
#include <shellApi.h>

#define WM_NOTIFYICON	WM_USER+5
#define RTN_ERROR 13

// CAutoPowerOnShutdownDlg dialog
class CAutoPowerOnShutdownDlg : public CDialog
{
// Construction
public:

	CAutoPowerOnShutdownDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_AUTOPOWERONSHUTDOWN_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:

	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

private:

	// static control used to draw digital clock
	CClockST m_StaticClock;
	afx_msg void OnBnClickedOk();
	afx_msg void OnBnClickedReset();
	afx_msg void OnBnClickedApply();
	afx_msg void OnBnClickedButtonShutdown();
	afx_msg void OnBnClickedButtonReboot();
	afx_msg void OnBnClickedButtonLogoff();
	afx_msg void OnBnClickedButtonHibernate();

private:

	//set the controls' state through 
	//ini file
	void InitFromIniFle(void);
	//shutdonw reboot logoff and son on...
	void ExitWindow(int CMDID);
	//set S3 or S4
	int SetPower(BOOL   bSuspend,BOOL   bForce);
	//get delay action and time par
	void GetDelayInfo();
	int GetCountDownTime();
	int GetSpecTime();
	
	//show hide and display in the tray
	void Add2Tray(void);
	//show hide in the tray
	void DelFromTray(void);
	
	void SetS4WakeTimer(unsigned char seconds);
private:

	//delay action
	enum ACTION {S3 = 1,S4,S5,REBOOT};
	//time type
	enum TIMEPARTYPE {SPECTIME = 1, COUNTDOWN};
	//time unit
	enum TIMEUNIT {SECOND = 1, MINUTE, HOUR};
	
	//delay info
	struct DelayInfo
	{
	 ACTION m_Act;
	 TIMEPARTYPE m_Par;
	 TIMEUNIT m_Unit;	
	 int m_ILoops;
	 int m_TimeSnd;
	};

	DelayInfo m_DlInf;

	//controls var
	CDateTimeCtrl m_DateTime;
	CEdit m_EditCount;
	CComboBox m_CombUnit;
	CEdit m_EditLoop;
	CStatic m_StaticLoop;
	CButton m_BtnSetAutoRun;
	
	//timer ID
	UINT uiTimerID;
	NOTIFYICONDATA m_nd;


private:
	//get DelayInfo from ini file
	void ReadIni(DelayInfo& dlInf);
	//exec Action
	void ActionGo(void);
	//check ini file is exist or not
	BOOL IsIniFileExist();
	//create default ini file
	void CreateDefaultIniFile();
	//save par to ini file
	void SavePar2IniFile();
	//check autorun is set or not
	//if set return true otherwise false
	BOOL IsAutoRunExit();
	//set app to auto run in reg
	BOOL SetAutoRun(CString appPath);
	//remove app auto run in reg
	BOOL RemoveAutoRun(CString cstrApp);
	//get the app's abs path
	CString GetMyPath();
	//action app by the condition
	void GoByCondition(void);

	void HideLoops(BOOL bHide);

protected:
	//windows proc
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	//on time proc
	static VOID WINAPI TimerProc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser,
                    DWORD_PTR dw1, DWORD_PTR dw2); 

public:
	//syscommand
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	//tray msg
	afx_msg LRESULT OnNotifyIcon(WPARAM wParam, LPARAM lParam);
	//destroy
	afx_msg void OnDestroy();

	afx_msg void OnBnClickedRadioCountdown();

	afx_msg void OnBnClickedRadioSpectime();

	afx_msg void OnBnClickedCheckAutorun();

	afx_msg void OnBnClickedRadios3();

	afx_msg void OnBnClickedRadios4();

	afx_msg void OnBnClickedRadios5();



};
